package com.lizhi.note.service;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenBlackListCacheService {

    private final Cache<String, Object> cache;

    public TokenBlackListCacheService() {
        cache = Caffeine.newBuilder()
                // 设置最后一次写入或访问后经过固定时间过期
                .expireAfterWrite(24, TimeUnit.HOURS)
                // 初始的缓存空间大小
                .initialCapacity(100)
                // 缓存的最大条数
                .maximumSize(1000)
                .build();
    }

    public boolean containsKey(String key) {
        return cache.getIfPresent(key) != null;
    }

    public void putElement(String key){
        cache.put(key, 1);
    }
}